﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace VisualExamEngine
{
    public partial class frmMain : Form
    {
        public frmMain()
        {
            InitializeComponent();
        }

        /// <summary>
        /// DateTime: 5/4/15 9:29 PM
        /// Author: Mike Hartwig
        /// Purpose: Exits the application and returns to the desktop
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void tsmExit_Click(object sender, EventArgs e)
        {
            //Exit the program
            Application.Exit();
        }

        /// <summary>
        /// DateTime: 5/4/15 9:40 PM
        /// Author: Mike Hartwig
        /// Purpose: Shows a new mdi child
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void tsmNew_Click(object sender, EventArgs e)
        {
            //Create the new mdi child
            frmMdiChild child = new frmMdiChild(this);

            //Create a new exam
            clsExam exam = new clsExam("Default Title");

            //set the tag
            child.Tag = exam;

            //Set the mdi parent
            child.MdiParent = this;

            //Set the mdi child title
            child.Text = "Exam " + this.MdiChildren.Length.ToString();

            //Show the mdi form
            child.Show();

            //menu items
            this.tsmClose.Enabled = true;
            this.tsmSave.Enabled = true;
            this.tsmSaveAs.Enabled = true;
            this.tsmPageSetup.Enabled = true;
            this.tsmPrint.Enabled = true;
            this.tsmPrintPreview.Enabled = true;
            this.tsmUndo.Enabled = true;
            this.tsmRedo.Enabled = true;
            this.tsmMoveTo.Enabled = true;
            this.tsmMoveDown.Enabled = true;
            this.tsmMoveUp.Enabled = true;
            this.tsmPreviousItem.Enabled = true;
            this.tsmNextItem.Enabled = true;
            this.tsmGoTo.Enabled = true;
            this.tsmExamProperties.Enabled = true;
            this.tsmNewQuestion.Enabled = true;
            this.tsmNewExam.Enabled = true;
            this.tsmSelect.Enabled = true;
            this.tsmCut.Enabled = true;
            this.tsmCopy.Enabled = true;
            this.tsmPaste.Enabled = true;
            this.tsmDelete.Enabled = true;
            this.tsmFind.Enabled = true;
            this.tsmFindNext.Enabled = true;
            this.tsmReplace.Enabled = true;

            //tool buttons
            this.tsbPrintPreview.Enabled = true;
            this.tsbReplace.Enabled = true;
            this.tsbRedo.Enabled = true;
            this.tsbUndo.Enabled = true;
            this.tsbSave.Enabled = true;
            this.tsbPrint.Enabled = true;
            this.tsbGoTo.Enabled = true;
            this.tsbNext.Enabled = true;
            this.tsbPrevious.Enabled = true;
            this.tsbPicture.Enabled = true;
            this.tsbCut.Enabled = true;
            this.tsbFind.Enabled = true;
            this.tsbCopy.Enabled = true;
            this.tsbPaste.Enabled = true;
        }

        /// <summary>
        /// DateTime: 5/4/15 9:44 PM
        /// Author: Mike Hartwig
        /// Purpose: Close the active mdi child
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void tsmClose_Click(object sender, EventArgs e)
        {
            //Close the mdi child form
            this.ActiveMdiChild.Close();
        }

        /// <summary>
        /// DateTime: 5/5/15 5:50 PM
        /// Author: Mike Hartwig
        /// Purpose: Hide the status bar or show the status bar
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void tsmStatusBar_Click(object sender, EventArgs e)
        {
            if (this.tsmStatusBar.Checked == false)
            {
                this.stsExamInfo.Visible = false;
            }
            else
            {
                this.stsExamInfo.Visible = true;
            }
        }

        /// <summary>
        /// DateTime: 5/6/15 5:50 PM
        /// Author: Mike Hartwig
        /// Purpose: Hide the standard toolbar or show
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void tsmStandardToolbar_Click(object sender, EventArgs e)
        {
            if (this.tsmStandardToolbar.Checked == false)
            {
                this.tosMain.Visible = false;
            }
            else
            {
                this.tosMain.Visible = true;
            }
        }

        /// <summary>
        /// DateTime: 5/6/15 7:50 PM
        /// Author: Mike Hartwig
        /// Purpose: Form Load event. Enable/Disable GUI Items.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void frmMain_Load(object sender, EventArgs e)
        {
            //menu items
            this.tsmClose.Enabled = false;
            this.tsmSave.Enabled = false;
            this.tsmSaveAs.Enabled = false;
            this.tsmPageSetup.Enabled = false;
            this.tsmPrint.Enabled = false;
            this.tsmPrintPreview.Enabled = false;
            this.tsmUndo.Enabled = false;
            this.tsmRedo.Enabled = false;
            this.tsmMoveTo.Enabled = false;
            this.tsmMoveDown.Enabled = false;
            this.tsmMoveUp.Enabled = false;
            this.tsmPreviousItem.Enabled = false;
            this.tsmNextItem.Enabled = false;
            this.tsmGoTo.Enabled = false;
            this.tsmExamProperties.Enabled = false;
            this.tsmNewQuestion.Enabled = false;
            this.tsmNewExam.Enabled = false;
            this.tsmSelect.Enabled = false;
            this.tsmCut.Enabled = false;
            this.tsmCopy.Enabled = false;
            this.tsmPaste.Enabled = false;
            this.tsmDelete.Enabled = false;
            this.tsmFind.Enabled = false;
            this.tsmFindNext.Enabled = false;
            this.tsmReplace.Enabled = false;

            //tool buttons
            this.tsbPrintPreview.Enabled = false;
            this.tsbReplace.Enabled = false;
            this.tsbRedo.Enabled = false;
            this.tsbUndo.Enabled = false;
            this.tsbSave.Enabled = false;
            this.tsbPrint.Enabled = false;
            this.tsbGoTo.Enabled = false;
            this.tsbNext.Enabled = false;
            this.tsbPrevious.Enabled = false;
            this.tsbPicture.Enabled = false;
            this.tsbCut.Enabled = false;
            this.tsbFind.Enabled = false;
            this.tsbCopy.Enabled = false;
            this.tsbPaste.Enabled = false;
        }

        /// <summary>
        /// DateTime: 5/6/15 11:50 PM
        /// Author: Mike Hartwig
        /// Purpose: Create a new exam.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void tsbNewExam_Click(object sender, EventArgs e)
        {
            this.tsmNew.PerformClick();
        }

        /// <summary>
        /// DateTime: 5/7/15 11:50 PM
        /// Author: Mike Hartwig
        /// Purpose: Show about dialog
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void tsmAbout_Click(object sender, EventArgs e)
        {
            frmAbout about = new frmAbout();
            about.ShowDialog();
        }

        /// <summary>
        /// DateTime: 5/7/15 10:50 PM
        /// Author: Mike Hartwig
        /// Purpose: Show about dialog
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void tsmNewQuestion_Click(object sender, EventArgs e)
        {
            frmQuestionType question = new frmQuestionType(this);
            question.ShowDialog();
        }

        /// <summary>
        /// DateTime: 5/7/15 11:50 PM
        /// Author: Mike Hartwig
        /// Purpose: Add a sub-exam
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void tsmNewExam_Click(object sender, EventArgs e)
        {
            TreeView trvExamExplorer = this.ActiveMdiChild.Controls.Find("trvExamExplorer", true).FirstOrDefault() as TreeView;

            trvExamExplorer.Nodes.Add("Exam " + clsUtilities.GetLetter(trvExamExplorer.Nodes.Count));
        }

        /// <summary>
        /// DateTime: 5/7/15 11:50 PM
        /// Author: Mike Hartwig
        /// Purpose: Exam menu item clicked on main form.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void tsmExam_Click(object sender, EventArgs e)
        {
            if (this.MdiChildren.Count() != 0)
            {
                TreeView trvExamExplorer = this.ActiveMdiChild.Controls.Find("trvExamExplorer", true).FirstOrDefault() as TreeView;

                if (trvExamExplorer.Nodes.Count >= 24)
                {
                    this.tsmNewExam.Enabled = false;
                }
                else
                {
                    this.tsmNewExam.Enabled = true;
                }
            }
        }

        /// <summary>
        /// DateTime: 5/8/15 7:50 AM
        /// Author: Mike Hartwig
        /// Purpose: Show the open file dialog
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void tsmOpen_Click(object sender, EventArgs e)
        {
            if (ofdExamOpen.ShowDialog() == DialogResult.OK)
            {

            }
        }

        private void tsmSelect_Click(object sender, EventArgs e)
        {

        }

        /// <summary>
        /// DateTime: 5/8/15 7:50 AM
        /// Author: Mike Hartwig
        /// Purpose: Show the print preview dialog 
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void tsmPrintPreview_Click(object sender, EventArgs e)
        {
            if (this.ppdPrintPreview.ShowDialog() == DialogResult.OK)
            {

            }
        }

        /// <summary>
        /// DateTime: 5/9/15 1:50 PM
        /// Author: Mike Hartwig
        /// Purpose: Show the exam properties dialog 
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void tsmExamProperties_Click(object sender, EventArgs e)
        {
            frmExamProperties examprop = new frmExamProperties((frmMdiChild) this.ActiveMdiChild);
            examprop.ShowDialog();
        }

        /// <summary>
        /// DateTime: 5/15/15 1:50 PM
        /// Author: Mike Hartwig
        /// Purpose: Show the move question dialog
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void tsmMoveTo_Click(object sender, EventArgs e)
        {
            frmMoveTo Move = new frmMoveTo(this);
            Move.ShowDialog();
        }

        /// <summary>
        /// DateTime: 5/16/15 1:50 PM
        /// Author: Mike Hartwig
        /// Purpose: Show the open file dialog
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void tsbOpenExam_Click(object sender, EventArgs e)
        {
            tsmOpen.PerformClick();
        }
    }
}
